<template>
  <!-- 驾照列表 -->
  <div class="container" >
    <div >
      <img src="@/assets/img/license.png" alt="" />
    <div class="search">
      <span style="margin-right: 5px">驾照类型</span>
      <el-input
        v-model="type"
        placeholder="驾照类型"
        style="width: 300px; margin-right: 10px"
      ></el-input>
      <el-button
        type="primary"
        @click="search"
        style="height: 40px"
        icon="el-icon-search"
        >搜索</el-button
      >
    </div>
    <div class="list">
      <div
        class="wrapper"
        v-for="(item, index) in licenseList"
        :key="index"
        @click="toDetail(item.id,item.type)"
      >
        <div class="little">
          <img :src="item.img" alt="" />
          <div>{{ item.type }}驾驶证</div>
        </div>
      </div>

      <el-pagination
        class="fenye"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[6, 8]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    </div>
    <el-dialog title="驾照详情" :visible.sync="infoStatus" width="50%">
      <el-form :model="info">
        <el-form-item style="width: 600px" label="头像">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
          >
            <img v-if="info.img" :src="info.img" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="驾照类型">
          <el-input v-model="info.type"></el-input>
        </el-form-item>
        <el-form-item label="准驾车型">
          <el-input v-model="info.car" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="报名价格">
          <el-input v-model="info.price" placeholder="请输入姓名"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="infoStatus = false">取 消</el-button>
        <el-button type="primary" @click="goApplication">报名</el-button>
      </span>
    </el-dialog>
  </div>
  
 
</template>

<script>
import { licenseList,getInfo,application,searchLicense } from "@/api/license";

export default {
  name: "License",
  data() {
    return {
      type: null,
      total: 0,
      licenseList: [],
      pageNumber: 1, //当前页
      pagesize: 8, //分页的数据
      infoStatus:false,
      info:{}
    };
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.getLicenseList();
    },
    handleCurrentChange(val) {
      this.pageNumber = val;
      this.getLicenseList();
    },
    async getLicenseList() {
      let res = await licenseList({
        pageNumber: this.pageNumber,
        pagesize: this.pagesize,
      });

      if (res.code == 200) {
        this.licenseList = res.data;
        this.total = res.totalCount;
      }
    },
    
    async toDetail(id,type) {
      this.infoStatus = true;
      this.type = type
      let res = await getInfo(id);
      console.log(res);
      if (res.code == 200) {
        this.info = res.data;
        this.$message({
          message: res.message,
          type: "success",
        });
      }
    },
    async goApplication() {
      let data = {};
      let infomation =  JSON.parse(localStorage.getItem('infomation'))
      data.nickname =infomation.nickname;
      data.type =this.type;
      data.photo = infomation.photo;
      console.log(data.photo);
      let res = await application(data);
      
      if (res.code == 200) {
        this.$message({
          message: res.message,
          type: "success",
        });
        this.infoStatus = false
      }
    },
    async search() {
      
      
      if (this.type==''){
        this.getLicenseList()
        return
      }
      let res = await searchLicense({type:this.type});
      if (res.code == 200) {
        this.$message({
          message: res.message,
          type: "success",
        });
        this.licenseList = res.data;
        this.total = res.data.length;
      }
    },
  },
  mounted() {
    this.getLicenseList();
  },
 
  
};
</script>

<style scoped lang="scss">
.container {
  width: 87%;

  box-shadow: 4px 4px 15px rgb(136, 116, 116);
  margin-left: 40px;
  padding: 20px 0;
  box-sizing: border-box;
  img {
    width: 100%;
  }
  .search {
    background-color: #999d9c;
    width: 100%;
    height: 60px;
    display: flex;
    line-height: 60px;
    padding-left: 60%;
    color: #ffffff;
    align-items: center;
  }
  .list {
    position: relative;
    width: 100%;
    height: 600px;
    padding-left: 10px;
    padding-top: 10px;
    padding-right: 10px;

    display: flex;
   
    flex-wrap: wrap;
    .fenye {
      position: absolute;
      bottom: 10px;
      left: 30%;
    }
    .wrapper {
      width: 250px;
      height: 250px;
      border: solid 5px #999d9c;
      border-radius: 10px;
      margin-left: 30px;

      .little {
        width: 90%;
        height: 90%;
        background-color: #999d9c;
        margin-top: 5%;
        margin-left: 5%;
        img {
          width: 100%;
          height: 80%;
        }
        div {
          text-align: center;
          line-height: 30px;
        }
      }
    }
  }
}
</style>
